Skip to content

feat(flutterwave): split payments across subaccounts - #102

Closed
alexasomba wants to merge 11 commits into
emdashCommerce:mainfrom
alexasomba:feat/flutterwave-splits
Closed

alexasomba wants to merge 11 commits into
emdashCommerce:mainfrom
alexasomba:feat/flutterwave-splits

Conversation

@alexasomba

@alexasomba alexasomba commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Part of the Flutterwave set described in #97. Item 5. Builds on #98 (the package), #100 (on-page) and #101 (the split allocation seam). Review those first; this branch contains their commits until they merge.

What

Flutterwave subaccount splits, for hosted and on-page checkout:

  • Declares capabilities.splits: true.

  • When core sends allocations, each becomes a Flutterwave subaccounts item:

    { "id": "RS_…", "transaction_charge_type": "flat_subaccount", "transaction_charge": 1350 }

    flat_subaccount pays the subaccount that exact amount, so core's minor-unit share maps one-to-one after the major-unit conversion. The platform keeps the remainder.

  • Hosted checkout sends the array on POST /v3/payments. On-page sends it as JSON in the create-session client payload; ./checkout-client parses it and passes the array to Inline.

  • Every share is validated before the provider call: no empty account, no non-positive amount, no total above the checkout amount, no negative platform remainder. A malformed split in the browser is refused rather than opening an unsplit payment.

What does not change

  • A cart without vendor items sends no subaccounts.
  • The order still comes only from the signed webhook and the live verify; a split does not change confirmation, dedupe or refunds.
  • Refunds are still taken from the platform balance by Flutterwave; the package does not attempt a subaccount clawback.

Tests

  • 90 package tests (was 82): hosted mapping, Inline JSON mapping, no allocations, empty account, zero share, shares above the total, and the browser parsing/refusing a split.
  • 346 core tests pass in this branch, including the split allocation seam and the product-to-vendor assignment fix from feat(core): split payments across vendor payout accounts #101.
  • Typecheck clean; build emits both entries; Biome clean on the touched files.

Split behaviour worth knowing

  • Flutterwave's transaction fee and the NGN 50 stamp duty (over NGN 10,000) come out of the platform remainder, not the vendor shares.
  • If the settlement is less than the sum of the flat amounts, Flutterwave does not split that payment and sends the whole settlement to the main account. The package cannot detect that before the provider's fee is known; the README tells the merchant to watch the dashboard for it.
  • Creating subaccounts via the Flutterwave API (bank details, KYC) is out of scope here: the merchant creates the subaccount in the dashboard and pastes the RS_… id into Vendors. A follow-up can add API-driven subaccount creation.

End to end in Flutterwave test mode (24 Nov 2026)

Check Result
Two collection subaccounts created RS_CD57… (Access Bank 0690000031) and RS_A075… (0690000032)
KES 1,500 two-vendor payment through the package's Inline client Succeeded, transaction 10633643
Vendor A share 900 KES
Vendor B share 450 KES
Platform remainder 76.5 KES, after Flutterwave's 73.5 KES fee
Flutterwave's own settlement metadata meta.split_settlement_info = { RS_CD57…: { subaccount_earning: 900 }, RS_A075…: { subaccount_earning: 450 }, total_merchant_commission: 76.5 }

The split is confirmed by Flutterwave's settlement record, not only by the payload we sent. A real verify response is committed as a fixture and parsed in the test suite.

Still to run: the real webhook delivery (a real KES 100 payment and two resend-hook calls were accepted on 24 Nov 2026, but nothing reached the test tunnel yet — the dashboard configuration is under review), and a refund on a split payment — Flutterwave refunds come from the platform balance and this package does not attempt a subaccount clawback.

@alexasomba

Copy link
Copy Markdown
Contributor Author

Superseded by #107 — the Flutterwave package is now reviewed as one PR. The commits are preserved on the consolidated branch, and the core PRs (#99, #101, #103, #105) stay separate.

@alexasomba alexasomba closed this Nov 24, 2026
cavewebs added a commit that referenced this pull request Nov 27, 2026
Part of the Flutterwave set described in #97. **Item 2** — a generic
core seam, independent of #85 (Paystack) and #98 (the Flutterwave
package). No Flutterwave code in core.

## Why

Flutterwave Inline, its on-page checkout, is a browser SDK initialised
with the account's **public** key (`FLWPUBK-…`). Core's provider
settings stored only `secretKey` and `webhookSecret`, and a provider has
no KV access, so the server could not hand the browser client the key it
needs.

The shortcut — deriving the public key from the secret key — is not
available. I checked a real test pair: `FLWPUBK_TEST-991d…` and
`FLWSECK_TEST-03d5…` have different hash segments.

## What

- `PaymentProviderCredentials.publicKey` and
`credentialFields.publicKey` (label, prefixes, help).
- `settings:<id>PublicKey` in the settings schema,
`providerCredentialSetting` and `GET admin/settings` `_providers`,
validated against the prefixes the provider declares and masked like the
other credentials.
- A third field in Settings → Payment provider, rendered **only** for a
provider that declares one.
- `loadPaymentProviderCredentials` returns `publicKey` when set.

## What does not change

- Stripe's fields, keys and behaviour.
- Providers that do not declare a public key: their settings row is
byte-for-byte the same, and a `publicKey` value is refused for them (so
a typo cannot save a key nothing reads).
- The secret key and webhook secret are still offered for every
provider, as before.

## Tests

- `provider-credentials-settings.test.ts`: saves and loads the public
key, validates its prefix, refuses one for a provider that does not
declare it, never returns the value (only set/hint), and omits the row
entirely for such a provider.
- 12 tests in that file, 58 across the
provider/credentials/webhook-header files, `tsc --noEmit` clean.
- Changeset: minor for `@dashcommerce/core`.

## Next

Item 3 is
[#100](#100): the
provider declares the field, returns `on_page` with `{ publicKey, txRef,
amount, currency, customer… }`, and ships a `./checkout-client` that
loads `checkout.flutterwave.com/v3.js` only when the customer presses
Pay. The split seams are
[#101](#101) (core)
and [#102](#102)
(Flutterwave). All are open.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant